package utils

import com.inamik.utils.SimpleTableFormatter
import com.inamik.utils.TableFormatter as TF
import com.aliasi.classify.JointClassification

class Utils {
    static printJointClassification(JointClassification classification) {
        def tf = new SimpleTableFormatter(true)
        def captions = "Rank§Category§Score§P(Category|Input)§log2 P(Category,Input)"
        tf.nextRow()
        captions.split(/§/).each {caption -> tf.nextCell().addLine(caption) }

        (0..<classification.size()).eachWithIndex { index, cat ->
            tf.nextRow()
            tf.nextCell(TableFormatter.ALIGN_RIGHT, TableFormatter.VALIGN_CENTER).addLine(index.toString())
            tf.nextCell(TableFormatter.ALIGN_CENTER, TableFormatter.VALIGN_CENTER).addLine(classification.category(index))
            tf.nextCell().addLine(classification.score(index).toString())
            tf.nextCell().addLine(classification.conditionalProbability(index).toString())
            tf.nextCell().addLine(classification.jointLog2Probability(index).toString())
        }
        tf.getFormattedTable().each {println it}
    }
}
